package org.coc.betterchicago;

import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.representation.StringRepresentation;
import org.restlet.routing.Router;

@SuppressWarnings("serial")
public class BetterChicagoInfo extends Application {
	/**
	 * Creates a root Restlet that will receive all incoming calls.
	 */
	@Override
	public synchronized Restlet createRoot() {
		// Create a router Restlet that routes each call to a new Resource
		Router router = new Router(getContext());

		// router.attach("/test", TestJsonResource.class);

		Restlet mainpage = new Restlet() {
			@Override
			public void handle(Request request, Response response) {
				try {
					JSONObject json = new JSONObject();
					json.put("success", false);
					json.put("error", "Service not available");

					JsonRepresentation jsonRep = new JsonRepresentation(json);
					response.setEntity(jsonRep);
				} catch (JSONException e) {
					response.setEntity(new StringRepresentation("{\"success\" : false, \"error\": \"Service not available\"}", MediaType.APPLICATION_JSON));
				}
			}
		};
		router.attach("", mainpage);
		return router;
	}
}
